//
//  NIESpecialAreaCollectionViewSectionHeader.m
//  NIESpider
//
//  Created by fanbo on 14/12/10.
//  Copyright (c) 2014年 FZCommon. All rights reserved.
//

#import "FZHomeCollectionViewSectionHeaderView.h"
#import <UIColor+Hex.h>
#import "FZStyleSheet.h"


@interface FZHomeCollectionViewSectionHeaderView ()
@property (weak, nonatomic) IBOutlet UIView *topLinebreakView;
@property (weak, nonatomic) IBOutlet UIView *bottomLinebreakView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tipsIconImageViewWidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelLeftConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLinebreakViewHeightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLinebreakViewHeightConstraint;

@end

@implementation FZHomeCollectionViewSectionHeaderView

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    
    //这个颜色值需要UI给出来
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    UIColor *lineBreakColor = [UIColor colorWithWhite:1 alpha:0.2f];
    self.topLinebreakView.backgroundColor = lineBreakColor;
    self.bottomLinebreakView.backgroundColor = lineBreakColor;
    [self hideBreakline];

    [self.moreButton setTitleColor:css.color_4 forState:UIControlStateNormal];
    [self.moreButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
    self.moreButton.titleLabel.font = css.fontOfH5;
//    [self.moreButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, P2PSZ(30))];
//    [self.moreButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -P2PSZ(50))];
//    self.tipsIconImageViewWidthConstraint.constant = P2PSZ(6);
//    self.titleLabelLeftConstraint.constant = P2PSZ(32);
    self.topLinebreakViewHeightConstraint.constant = 0.5;
    self.bottomLinebreakViewHeightConstraint.constant = 0.5;
    self.titleLabel.font = css.fontOfH5;
    self.titleLabel.textColor = css.color_4;
    
    self.rankImageView.hidden = YES;
    self.backgroundColor = css.color_5;
//    UIView *bgView = [[UIView alloc] init];
//    bgView.backgroundColor = css.color_2;
//    [self addSubview:bgView];
//    
//    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.trailing.top.bottom.equalTo(self);
//    }];
//    
//    [self sendSubviewToBack:bgView];
    
    WEAKSELF
    [self addTapGestureHandler:^(UITapGestureRecognizer *gestureRecognizer, UIView *view, CGPoint locationInView) {
        if (weakSelf.headerSectionActionBlock) {
            weakSelf.headerSectionActionBlock(weakSelf.indexPath, weakSelf.headerModule);
        }
    }];
}

- (void)hideBreakline {
    self.topLinebreakView.hidden = YES;
    self.bottomLinebreakView.hidden = YES;
}

- (IBAction)moreAction:(id)sender {
    if (self.headerActionBlock) {
        self.headerActionBlock(self.indexPath, self.headerModule);
    }
}

- (void)setIconImageHidden:(BOOL)iconImageHidden {
    _iconImageHidden = iconImageHidden;
    
    if (iconImageHidden) {
        self.tipsIconImageViewWidthConstraint.constant = 0;
        self.titleLabelLeftConstraint.constant = 0;
    }
    else {
        self.tipsIconImageViewWidthConstraint.constant = 26;
        self.titleLabelLeftConstraint.constant = 8;
    }
    
}

@end
